package com.hkyl.hospital.web.controller;

import com.github.pagehelper.PageInfo;
import com.hkyl.hospital.domain.ResultVo;
import com.hkyl.hospital.entity.Operation;
import com.hkyl.hospital.entity.Sickroom;
import com.hkyl.hospital.service.SickRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author gao
 * @date 2023/07/13 14:53:00
 */
@RestController
@RequestMapping("sickroom")
public class SickRoomController {
    @Autowired
    private SickRoomService sickRoomService;
    @PostMapping("findAll")
    public ResultVo findAll(@RequestBody Map map){
        Integer pageNumber = (Integer) map.get("pageNumber");
        Integer pageSize = (Integer) map.get("pageSize");
        List<Sickroom> someByPage = sickRoomService.findSomeByPage(pageNumber, pageSize);
        return ResultVo.success(someByPage);
    }
    @PostMapping("search")
    public ResultVo search(@RequestBody Map map){
        String sickroomCode= (String) map.get("sickroomCode");
        String nurseName= (String) map.get("nurseName");
        Integer pageNumber = (Integer) map.get("pageNumber");
        Integer pageSize = (Integer) map.get("pageSize");
        PageInfo<Sickroom>sickrooms=new PageInfo<>(sickRoomService.search(sickroomCode,nurseName,pageNumber,pageSize));
        return ResultVo.success(sickrooms);
    }
    @PostMapping("save")
    public ResultVo insert(@RequestBody Sickroom sickroom){
        int rows = sickRoomService.insert(sickroom);
        return  rows>0?ResultVo.success("添加成功"):ResultVo.failure("添加失败");
    }
    @PostMapping("update")
    public ResultVo update(@RequestBody Sickroom sickroom){
        int rows = sickRoomService.update(sickroom);
        return  rows>0?ResultVo.success("修改成功"):ResultVo.failure("修改失败");
    }
    @PostMapping("changeStatus")
    public ResultVo delete(@RequestBody String sickroomId){
        if(!StringUtils.hasText(sickroomId)){
            throw  new RuntimeException("不存在输入的id");
        }
        int rows = sickRoomService.changeStatus(Integer.valueOf(sickroomId));
        return  rows>0?ResultVo.success("切换成功"):ResultVo.failure("切换失败");
    }
}
